package com.itheima.tlias84.servrce.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tlias84.dto.SelectStudentsDTO;
import com.itheima.tlias84.mapper.StudentsMapper;
import com.itheima.tlias84.po.InsertClazzParam;
import com.itheima.tlias84.po.InsertStudetsParam;
import com.itheima.tlias84.po.SelectStudentPageParam;
import com.itheima.tlias84.servrce.StudentsService;
import com.itheima.tlias84.utils.ResultUtil;
import com.itheima.tlias84.vo.ClazzPageVO;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentsServicempl implements StudentsService {
    @Resource
    StudentsMapper studentsMapper;

    @Override
    public int insertStudents(InsertStudetsParam Param) {
        int i = studentsMapper.insertStudents(Param);
        return i;

    }

    @Override
    public ResultUtil selelectStudentsPageParam(SelectStudentPageParam PageParam) {
        // 计算 页数 和 每页展示的数量   的代码
        Page<Object> objects = PageHelper.startPage(PageParam.getPage(), PageParam.getPageSize());
        List<SelectStudentsDTO> dtos = studentsMapper.selelectStudentsPageParam(PageParam);
        ClazzPageVO clazzPageVO = new ClazzPageVO();
        clazzPageVO.setTotal(objects.getTotal());
        clazzPageVO.setRows(dtos);
        return ResultUtil.success(clazzPageVO);
    }
}
